package com.kingdee.eas.hr.emp.app;

import java.sql.Timestamp;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.IObjectValue;
import com.kingdee.bos.dao.ormapping.ObjectStringPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.eas.basedata.person.PersonFactory;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.hr.emp.PersonFamilyCollection;
import com.kingdee.eas.hr.emp.PersonFamilyInfo;

public class PersonFamilyControllerBeanEx extends PersonFamilyControllerBean {

//	@Override
//	protected IObjectPK _submit(Context ctx, IObjectValue model) throws BOSException, EASBizException {
//		IObjectPK pk = super._submit(ctx, model);
//		PersonFamilyInfo personFamilyInfo = (PersonFamilyInfo) model;
//
//		PersonInfo personInfo = personFamilyInfo.getPerson();
//		personInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(
//				new ObjectStringPK(personInfo.getId().toString()));
//
//		personInfo.setPersonFamily_2(personInfo.getPersonFamily_1());
//		personInfo.setPersonFamily_1(personFamilyInfo);
//
//		PersonFactory.getLocalInstance(ctx).submit(personInfo);
//
//		return pk;
//	}
//
//	@Override
//	protected void _delete(Context ctx, IObjectPK pk) throws BOSException, EASBizException {
//		PersonFamilyInfo personFamilyInfo = this.getPersonFamilyInfo(ctx, pk);
//		PersonInfo personInfo = personFamilyInfo.getPerson();
//		personInfo = PersonFactory.getLocalInstance(ctx).getPersonInfo(
//				new ObjectStringPK(personInfo.getId().toString()));
//
//		if (personInfo.getPersonFamily_1().getId().equals(personFamilyInfo.getId())) {
//			personInfo.setPersonFamily_1(this.getLastPersonFamilyInfoByPerson(ctx, personInfo,personFamilyInfo));
//		}
//
//		if (personInfo.getPersonFamily_2().getId().equals(personFamilyInfo.getId())) {
//			personInfo.setPersonFamily_2(this.getLastPersonFamilyInfoByPerson(ctx, personInfo,personFamilyInfo));
//		}
//		super._delete(ctx, pk);
//	}
//
//	protected PersonFamilyInfo getLastPersonFamilyInfoByPerson(Context ctx, PersonInfo personInfo,
//			PersonFamilyInfo personFamilyInfo) throws BOSException {
//		EntityViewInfo params = new EntityViewInfo();
//		FilterInfo filter = new FilterInfo();
//		filter.getFilterItems().add(new FilterItemInfo("person.id", personInfo.getId(), CompareType.EQUALS));
//		filter.getFilterItems().add(new FilterItemInfo("id", personFamilyInfo.getId(), CompareType.NOTEQUALS));
//		params.setFilter(filter);
//
//		PersonFamilyCollection collection = this.getPersonFamilyCollection(ctx, params);
//
//		PersonFamilyInfo temp = null;
//		PersonFamilyInfo retValue = null;
//
//		Timestamp lastUpdateTime = null;
//		for (int i = 0; i < collection.size(); i++) {
//			temp = collection.get(i);
//			if (lastUpdateTime == null) {
//				temp.getLastUpdateTime();
//				retValue = temp;
//			} else {
//				if (lastUpdateTime.before(temp.getLastUpdateTime())) {
//					retValue = temp;
//				}
//			}
//		}
//
//		return retValue;
//	}
}
